{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f1ec2b00",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "25938d37",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     Unnamed: 0             date max temperature min temperature weather  \\\n",
      "0             0  2018-01-01 星期一              13℃              0℃       霾   \n",
      "1             1  2018-01-02 星期二              10℃              5℃       雨   \n",
      "2             2  2018-01-03 星期三               8℃              1℃       雪   \n",
      "3             3  2018-01-04 星期四               3℃             -1℃       雪   \n",
      "4             4  2018-01-05 星期五               0℃             -3℃       阴   \n",
      "..          ...              ...             ...             ...     ...   \n",
      "480         480  2019-04-26 星期五              17℃             11℃      多云   \n",
      "481         481  2019-04-27 星期六              21℃             12℃    多云转雨   \n",
      "482         482  2019-04-28 星期日              17℃             13℃     阴转雨   \n",
      "483         483  2019-04-29 星期一              17℃             12℃      多云   \n",
      "484         484  2019-04-30 星期二              23℃             14℃      多云   \n",
      "\n",
      "       wind  \n",
      "0    东南风 3级  \n",
      "1    东北风 3级  \n",
      "2    东北风 4级  \n",
      "3    东北风 4级  \n",
      "4     北风 2级  \n",
      "..      ...  \n",
      "480  东北风 3级  \n",
      "481   东风 4级  \n",
      "482  东北风 2级  \n",
      "483   北风 2级  \n",
      "484   北风 2级  \n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "data_weather = pd.read_csv('F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_weather\\\\hefei_weather.csv')\n",
    "print(data_weather)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e7dacf75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'date', 'max temperature', 'min temperature', 'weather',\n",
       "       'wind'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_weather.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "90346aca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                date max temperature min temperature weather    wind\n",
      "0    2018-01-01 星期一              13℃              0℃       霾  东南风 3级\n",
      "1    2018-01-02 星期二              10℃              5℃       雨  东北风 3级\n",
      "2    2018-01-03 星期三               8℃              1℃       雪  东北风 4级\n",
      "3    2018-01-04 星期四               3℃             -1℃       雪  东北风 4级\n",
      "4    2018-01-05 星期五               0℃             -3℃       阴   北风 2级\n",
      "..               ...             ...             ...     ...     ...\n",
      "480  2019-04-26 星期五              17℃             11℃      多云  东北风 3级\n",
      "481  2019-04-27 星期六              21℃             12℃    多云转雨   东风 4级\n",
      "482  2019-04-28 星期日              17℃             13℃     阴转雨  东北风 2级\n",
      "483  2019-04-29 星期一              17℃             12℃      多云   北风 2级\n",
      "484  2019-04-30 星期二              23℃             14℃      多云   北风 2级\n",
      "\n",
      "[485 rows x 5 columns]\n"
     ]
    }
   ],
   "source": [
    "# 删除unnamed列\n",
    "data_weather = data_weather.drop('Unnamed: 0', axis=1)\n",
    "print(data_weather)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b2849660",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0      2018-01-01 星期一 \n",
      "1      2018-01-02 星期二 \n",
      "2      2018-01-03 星期三 \n",
      "3      2018-01-04 星期四 \n",
      "4      2018-01-05 星期五 \n",
      "            ...       \n",
      "480    2019-04-26 星期五 \n",
      "481    2019-04-27 星期六 \n",
      "482    2019-04-28 星期日 \n",
      "483    2019-04-29 星期一 \n",
      "484    2019-04-30 星期二 \n",
      "Name: date, Length: 485, dtype: object\n",
      "485\n",
      "2018-01-01 星期一 \n",
      "2018-01-01 星期一 \n"
     ]
    }
   ],
   "source": [
    "data_date = data_weather['date']\n",
    "print(data_date)\n",
    "print(len(data_date))\n",
    "print(data_date[0])\n",
    "print(data_weather['date'][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c286a3e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    max temperature min temperature weather    wind        date weekday\n",
      "0               13℃              0℃       霾  东南风 3级  2018-01-01    星期一 \n",
      "1               10℃              5℃       雨  东北风 3级  2018-01-02    星期二 \n",
      "2                8℃              1℃       雪  东北风 4级  2018-01-03    星期三 \n",
      "3                3℃             -1℃       雪  东北风 4级  2018-01-04    星期四 \n",
      "4                0℃             -3℃       阴   北风 2级  2018-01-05    星期五 \n",
      "..              ...             ...     ...     ...         ...     ...\n",
      "480             17℃             11℃      多云  东北风 3级  2019-04-26    星期五 \n",
      "481             21℃             12℃    多云转雨   东风 4级  2019-04-27    星期六 \n",
      "482             17℃             13℃     阴转雨  东北风 2级  2019-04-28    星期日 \n",
      "483             17℃             12℃      多云   北风 2级  2019-04-29    星期一 \n",
      "484             23℃             14℃      多云   北风 2级  2019-04-30    星期二 \n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "# 将date中日期与星期几分开然后重新合并至data_weather中\n",
    "data_show = pd.merge(data_weather, data_weather['date'].str.split(' ', 1, expand=True), how='left', left_index=True, right_index=True)\n",
    "data_show = data_show.drop('date',axis=1)\n",
    "data_show.rename(columns={0:'date',1:'weekday'}, inplace=True)\n",
    "print(data_show)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d6ed7009",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['max temperature', 'min temperature', 'weather', 'wind', 'date',\n",
      "       'weekday'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(data_show.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "581925ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    max temperature min temperature weather    wind        date weekday\n",
      "0                13               0       霾  东南风 3级  2018-01-01    星期一 \n",
      "1                10               5       雨  东北风 3级  2018-01-02    星期二 \n",
      "2                 8               1       雪  东北风 4级  2018-01-03    星期三 \n",
      "3                 3              -1       雪  东北风 4级  2018-01-04    星期四 \n",
      "4                 0              -3       阴   北风 2级  2018-01-05    星期五 \n",
      "..              ...             ...     ...     ...         ...     ...\n",
      "480              17              11      多云  东北风 3级  2019-04-26    星期五 \n",
      "481              21              12    多云转雨   东风 4级  2019-04-27    星期六 \n",
      "482              17              13     阴转雨  东北风 2级  2019-04-28    星期日 \n",
      "483              17              12      多云   北风 2级  2019-04-29    星期一 \n",
      "484              23              14      多云   北风 2级  2019-04-30    星期二 \n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "# 去除温度字符串最后一位\n",
    "def removeStr(data):\n",
    "    data['max temperature'] = data['max temperature'][:-1]\n",
    "    data['min temperature'] = data['min temperature'][:-1]\n",
    "#     data['date'].replace(\"-\",\"\")\n",
    "    return data\n",
    "\n",
    "data_show = data_show.loc[:].apply(removeStr, axis=1)\n",
    "print(data_show)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "98773336",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    max temperature min temperature weather    wind      date weekday\n",
      "0                13               0       霾  东南风 3级  20180101    星期一 \n",
      "1                10               5       雨  东北风 3级  20180102    星期二 \n",
      "2                 8               1       雪  东北风 4级  20180103    星期三 \n",
      "3                 3              -1       雪  东北风 4级  20180104    星期四 \n",
      "4                 0              -3       阴   北风 2级  20180105    星期五 \n",
      "..              ...             ...     ...     ...       ...     ...\n",
      "480              17              11      多云  东北风 3级  20190426    星期五 \n",
      "481              21              12    多云转雨   东风 4级  20190427    星期六 \n",
      "482              17              13     阴转雨  东北风 2级  20190428    星期日 \n",
      "483              17              12      多云   北风 2级  20190429    星期一 \n",
      "484              23              14      多云   北风 2级  20190430    星期二 \n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "# 将日期中的“-”换掉\n",
    "data_show['date'] = data_show['date'].str.replace(\"-\",\"\")\n",
    "print(data_show)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "52fb68c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data_show.to_csv('F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_weather\\\\hefei_weather_pro.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "db7ad90f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     max temperature  min temperature weather    wind      date weekday\n",
      "0                 13                0       霾  东南风 3级  20180101    星期一 \n",
      "1                 10                5       雨  东北风 3级  20180102    星期二 \n",
      "2                  8                1       雪  东北风 4级  20180103    星期三 \n",
      "3                  3               -1       雪  东北风 4级  20180104    星期四 \n",
      "4                  0               -3       阴   北风 2级  20180105    星期五 \n",
      "..               ...              ...     ...     ...       ...     ...\n",
      "480               17               11      多云  东北风 3级  20190426    星期五 \n",
      "481               21               12    多云转雨   东风 4级  20190427    星期六 \n",
      "482               17               13     阴转雨  东北风 2级  20190428    星期日 \n",
      "483               17               12      多云   北风 2级  20190429    星期一 \n",
      "484               23               14      多云   北风 2级  20190430    星期二 \n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "# data_show = pd.read_csv('F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_weather\\\\hefei_weather_pro.csv')\n",
    "# print(data_show)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cf04a779",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     Unnamed: 0      date week_cn  weekend  workday  holiday_legal  \\\n",
      "0             0  20180131     星期三        2        1              2   \n",
      "1             1  20180130     星期二        2        1              2   \n",
      "2             2  20180129     星期一        2        1              2   \n",
      "3             3  20180128     星期日        1        2              2   \n",
      "4             4  20180127     星期六        1        2              2   \n",
      "..          ...       ...     ...      ...      ...            ...   \n",
      "480         480  20190405     星期五        2        2              1   \n",
      "481         481  20190404     星期四        2        1              2   \n",
      "482         482  20190403     星期三        2        1              2   \n",
      "483         483  20190402     星期二        2        1              2   \n",
      "484         484  20190401     星期一        2        1              2   \n",
      "\n",
      "     holiday_recess  \n",
      "0                 2  \n",
      "1                 2  \n",
      "2                 2  \n",
      "3                 2  \n",
      "4                 2  \n",
      "..              ...  \n",
      "480               1  \n",
      "481               2  \n",
      "482               2  \n",
      "483               2  \n",
      "484               2  \n",
      "\n",
      "[485 rows x 7 columns]\n",
      "Index(['Unnamed: 0', 'date', 'week_cn', 'weekend', 'workday', 'holiday_legal',\n",
      "       'holiday_recess'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "data_holiday = pd.read_csv(\"F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_holiday\\\\holiday.csv\")\n",
    "print(data_holiday)\n",
    "print(data_holiday.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0c2631e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         date week_cn  weekend  workday  holiday_legal  holiday_recess\n",
      "0    20180131     星期三        2        1              2               2\n",
      "1    20180130     星期二        2        1              2               2\n",
      "2    20180129     星期一        2        1              2               2\n",
      "3    20180128     星期日        1        2              2               2\n",
      "4    20180127     星期六        1        2              2               2\n",
      "..        ...     ...      ...      ...            ...             ...\n",
      "480  20190405     星期五        2        2              1               1\n",
      "481  20190404     星期四        2        1              2               2\n",
      "482  20190403     星期三        2        1              2               2\n",
      "483  20190402     星期二        2        1              2               2\n",
      "484  20190401     星期一        2        1              2               2\n",
      "\n",
      "[485 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "data_holiday = data_holiday.drop(\"Unnamed: 0\", axis=1)\n",
    "print(data_holiday)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5bbd2ffe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     max temperature  min temperature weather    wind      date weekday  \\\n",
      "0                 13                0       霾  东南风 3级  20180101    星期一    \n",
      "1                 10                5       雨  东北风 3级  20180102    星期二    \n",
      "2                  8                1       雪  东北风 4级  20180103    星期三    \n",
      "3                  3               -1       雪  东北风 4级  20180104    星期四    \n",
      "4                  0               -3       阴   北风 2级  20180105    星期五    \n",
      "..               ...              ...     ...     ...       ...     ...   \n",
      "480               17               11      多云  东北风 3级  20190426    星期五    \n",
      "481               21               12    多云转雨   东风 4级  20190427    星期六    \n",
      "482               17               13     阴转雨  东北风 2级  20190428    星期日    \n",
      "483               17               12      多云   北风 2级  20190429    星期一    \n",
      "484               23               14      多云   北风 2级  20190430    星期二    \n",
      "\n",
      "    week_cn  weekend  workday  holiday_legal  holiday_recess  \n",
      "0       星期一        2        2              1               1  \n",
      "1       星期二        2        1              2               2  \n",
      "2       星期三        2        1              2               2  \n",
      "3       星期四        2        1              2               2  \n",
      "4       星期五        2        1              2               2  \n",
      "..      ...      ...      ...            ...             ...  \n",
      "480     星期五        2        1              2               2  \n",
      "481     星期六        1        2              2               2  \n",
      "482     星期日        1        1              2               2  \n",
      "483     星期一        2        1              2               2  \n",
      "484     星期二        2        1              2               2  \n",
      "\n",
      "[485 rows x 11 columns]\n"
     ]
    }
   ],
   "source": [
    "data = pd.merge(data_show,data_holiday)\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "03272900",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.drop(\"weekday\",axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ab432b6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['max temperature', 'min temperature', 'weather', 'wind', 'date',\n",
       "       'week_cn', 'weekend', 'workday', 'holiday_legal', 'holiday_recess'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7b5fffef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data.to_csv(\"F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_process\\\\hefei_data.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "cafdf88f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         date  max temperature  min temperature weather    wind week_cn  \\\n",
      "0    20180101               13                0       霾  东南风 3级     星期一   \n",
      "1    20180102               10                5       雨  东北风 3级     星期二   \n",
      "2    20180103                8                1       雪  东北风 4级     星期三   \n",
      "3    20180104                3               -1       雪  东北风 4级     星期四   \n",
      "4    20180105                0               -3       阴   北风 2级     星期五   \n",
      "..        ...              ...              ...     ...     ...     ...   \n",
      "480  20190426               17               11      多云  东北风 3级     星期五   \n",
      "481  20190427               21               12    多云转雨   东风 4级     星期六   \n",
      "482  20190428               17               13     阴转雨  东北风 2级     星期日   \n",
      "483  20190429               17               12      多云   北风 2级     星期一   \n",
      "484  20190430               23               14      多云   北风 2级     星期二   \n",
      "\n",
      "     weekend  workday  holiday_legal  holiday_recess  \n",
      "0          2        2              1               1  \n",
      "1          2        1              2               2  \n",
      "2          2        1              2               2  \n",
      "3          2        1              2               2  \n",
      "4          2        1              2               2  \n",
      "..       ...      ...            ...             ...  \n",
      "480        2        1              2               2  \n",
      "481        1        2              2               2  \n",
      "482        1        1              2               2  \n",
      "483        2        1              2               2  \n",
      "484        2        1              2               2  \n",
      "\n",
      "[485 rows x 10 columns]\n"
     ]
    }
   ],
   "source": [
    "data = data[['date','max temperature', 'min temperature', 'weather', 'wind',\n",
    "       'week_cn', 'weekend', 'workday', 'holiday_legal', 'holiday_recess']]\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b5aecbcf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data.to_csv(\"F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_process\\\\hefei_data.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "16a47ce5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          max temperature  min temperature weather    wind week_cn  weekend  \\\n",
      "date                                                                          \n",
      "20180101               13                0       霾  东南风 3级     星期一        2   \n",
      "20180102               10                5       雨  东北风 3级     星期二        2   \n",
      "20180103                8                1       雪  东北风 4级     星期三        2   \n",
      "20180104                3               -1       雪  东北风 4级     星期四        2   \n",
      "20180105                0               -3       阴   北风 2级     星期五        2   \n",
      "...                   ...              ...     ...     ...     ...      ...   \n",
      "20190426               17               11      多云  东北风 3级     星期五        2   \n",
      "20190427               21               12    多云转雨   东风 4级     星期六        1   \n",
      "20190428               17               13     阴转雨  东北风 2级     星期日        1   \n",
      "20190429               17               12      多云   北风 2级     星期一        2   \n",
      "20190430               23               14      多云   北风 2级     星期二        2   \n",
      "\n",
      "          workday  holiday_legal  holiday_recess  \n",
      "date                                              \n",
      "20180101        2              1               1  \n",
      "20180102        1              2               2  \n",
      "20180103        1              2               2  \n",
      "20180104        1              2               2  \n",
      "20180105        1              2               2  \n",
      "...           ...            ...             ...  \n",
      "20190426        1              2               2  \n",
      "20190427        2              2               2  \n",
      "20190428        1              2               2  \n",
      "20190429        1              2               2  \n",
      "20190430        1              2               2  \n",
      "\n",
      "[485 rows x 9 columns]\n"
     ]
    }
   ],
   "source": [
    "data = data.set_index(\"date\")\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c2533138",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data.to_csv(\"F:\\\\DeepLearning\\\\big-data-analysis\\\\data_requests\\\\data_process\\\\hefei_data1.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18d1aadb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
